
adminApp.controller('loginCtl' , function($scope,$http,$state){
    $scope.invalid = false;
    $scope.login = function(){
        $http.post("/uj-admin/login", $scope.user).success(function(){
            $state.go('index.taskMng');
        }).error(function(){
            $scope.invalid = true;
        });
    }

});

adminApp.controller('taskMngCtrl' , function($scope,$http,$state,$stateParams){

    $http.get("/uj-admin/task/list").success(function(data){
        $scope.list = data;
    });

    $scope.refresh = function(){
        $http.post("/uj-admin/task/refresh").success(function(data){
            $scope.list = data;
        });
    };

    $scope.go = function(type){
        if( type === 'order'){
            $state.go('index.orderMng');
        }

        if( type === 'withdraw'){
            $state.go('index.withdrawMng');
        }

        if( type === 'repurchase'){
            $state.go('index.repurchaseMng');
        }

    }

});

adminApp.controller('goodsMngCtrl' , function($scope,$http,$state,$stateParams,countryService, categoryService, wineryService){
    $scope.search = {};
    $scope.search.pageIndex = 0;
    $scope.search.pageSize = 10;

    $scope.$watch('search.cate_id_1', function() {
        $scope.search.cate_id_2 = null;
    });

    countryService.getCountryList().success(function(data){
        $scope.countries = data;
    });

    categoryService.getCategoryList().success(function(data){
        $scope.categoryList = data;
    });

    wineryService.getList().success(function(data){
        $scope.wineryList = data;
    });


    $scope.getPagedDataAsync = function(){
        $http.post("/uj-admin/goods/list", $scope.search).success(function(data){

            $scope.list = data.list;
            $scope.count = data.count;
        });

    };

    $scope.pagedCallback = function (){
        $scope.search.pageIndex = $scope.pageIndex -1;
        $scope.getPagedDataAsync();
    };

    $scope.getPagedDataAsync();

    $scope.statusChange = function(){
        if($scope.goods.closed == 1){
            $scope.goods.closed = 0;
            $scope.goods.close_reason = "";
        }
        else
            $scope.goods.closed = 1;
        $http.put('/uj-admin/goods/closed', $scope.goods).success(function (data) {
        });
    };

    $scope.setGoods = function(item){
        $scope.goods = item;
    }
});

adminApp.controller('goodsFormCtrl' , function($scope,$http,$state,$stateParams,wineryService , goodsService,categoryService,countryService){

    $scope.goods = {};
    $scope.goods.sales = 0;
    $scope.goods.isNew = 0;
    $scope.goods.recommended = 0;
    $scope.goods.hot = 0;

    $scope.$watch('goods.cate_id_1', function( newValue, oldValue ) {
        if(typeof(oldValue) != 'undefined')
            $scope.goods.cate_id_2 = null;
    });

    $scope.tagList = ['每日推荐','每周精选', '女性专享','名庄特卖','餐酒优选','超值礼包','恒温酒柜','爆款清仓'];
    $scope.selectTag = function(tag){
        if(typeof($scope.goods) == 'undefined')
            return;

        if(typeof(tag) == 'undefined')
            return;

        if($scope.hasTag(tag))
        {
            $scope.goods.tags = $scope.goods.tags.replace("," + tag, '');
        }
        else{
            $scope.goods.tags = typeof($scope.goods.tags) == 'undefined' ?  tag : $scope.goods.tags + ',' + tag;
        }

    };

    $scope.closeModal = function () {
        $("#closeModal").modal('hide');

        $('#closeModal').on('hidden.bs.modal', function (e) {
            $state.go('index.goodsMng');
        })

    };


    $scope.hasTag = function(tag){
        if(typeof($scope.goods) == 'undefined' || typeof($scope.goods.tags) == 'undefined')
            return;

        if(typeof(tag) == 'undefined')
            return;

        return $scope.goods.tags.indexOf(tag) > -1;
    };

    wineryService.getList().success(function(data){
        $scope.wineryList = data;
    });

    categoryService.getCategoryList().success(function(data){
        $scope.categoryList = data;
    });

    countryService.getCountryList().success(function(data){
        $scope.countries = data;
    });

    if($stateParams.id > 0){
       goodsService.getById($stateParams.id).success(function(data){
           $scope.goods = data;
       });
    }

    $scope.save = function(){
        //更新
        if($stateParams.id > 0) {
            $http.put('/uj-admin/goods', $scope.goods).success(function (data) {
                $state.go('index.goodsMng');
            });

        }
        //新增
        else{
            $http.post('/uj-admin/goods/add', $scope.goods).success(function (data) {
                $state.go('index.goodsMng');
            });
        }

    };

    $scope.onChange = function(status){
        switch(status){
            case 1:
                $scope.goods.sales = ($scope.goods.sales < 1 ?  1 : 0);
                break;
            case 2:
                $scope.goods.isNew = ($scope.goods.isNew < 1 ?  1 : 0);
                break;
            case 3:
                $scope.goods.recommended = ($scope.goods.recommended < 1 ?  1 : 0);
                break;
            case 4:
                $scope.goods.hot = ($scope.goods.hot < 1 ?  1 : 0);
                break;
        }
    }
});

adminApp.controller('goodsUploadCtrl' , function($scope,$http,$state,$stateParams, FileUploader){
    $scope.id = $stateParams.id;

    var uploadList = [] ;

    for(var i =0; i< 9; i++){

        var uploader = new FileUploader({
            url: '/uj-admin/goods/upload',
            index: i
        });
        // FILTERS
        uploader.filters.push({
            name: 'imageFilter',
            fn: function(item /*{File|FileLikeObject}*/, options) {
                var type = '|' + item.type.slice(item.type.lastIndexOf('/') + 1) + '|';
                return '|jpg|png|jpeg|bmp|gif|'.indexOf(type) !== -1;
            }
        });

        uploader.onAfterAddingFile = function(fileItem) {
            fileItem.formData.push({"index": this.index});
            fileItem.formData.push({"id": $stateParams.id});
            fileItem.upload();
        };

        uploader.onSuccessItem = function(fileItem, response, status, headers) {

            $("#img" + this.index).attr("src", $("#img" + this.index).attr("src")+"?timestamp=" + new Date().getTime());
        };

        uploader.onErrorItem = function(fileItem, response, status, headers) {
            if(response.errorCode == "LoginRequired")
            {
                window.location = '/uj-admin';
                return;
            }

            alert("请上传像素大于800*800的图片");
        };
        uploadList.push(uploader);
    }


    $scope.uploader0 = uploadList[0];
    $scope.uploader1 = uploadList[1];
    $scope.uploader2 = uploadList[2];
    $scope.uploader3 = uploadList[3];
    $scope.uploader4 = uploadList[4];

    $scope.uploader5 = uploadList[5];
    $scope.uploader6 = uploadList[6];
    $scope.uploader7 = uploadList[7];
    $scope.uploader8 = uploadList[8];
});

adminApp.controller('wineryMngCtrl', function($scope,$http,$state,$stateParams,$location,wineryService){
    $scope.search = {};

    wineryService.getList().success(function(data){
        $scope.list = data;
    });

    $scope.delete = function(id){
        $http.delete('/uj-admin/winery/' + id).success(function(data){
            for(var i = 0;i < $scope.list.length ; i++){
                if($scope.list[i].id == id){
                    $scope.list.splice(i,1);
                    return;
                }
            }
        })
    }
});

adminApp.controller('wineryFormCtrl', function($scope,$http,$state,$stateParams,wineryService){
    if($stateParams.id > 0){
        wineryService.getById($stateParams.id).success(function(data){
            $scope.winery = data;
        })
    }

    $scope.save = function(){
        if($stateParams.id > 0){
            $http.put('/uj-admin/winery', $scope.winery).success(function(data){
                $state.go('index.wineryMng');
            })
        }
        else{
            $http.post('/uj-admin/winery/add', $scope.winery).success(function(data){
                $state.go('index.wineryMng');
            })
        }
    }
});

adminApp.controller('wineryUploadCtrl' , function($scope,$http,$state,$stateParams, FileUploader){
    $scope.id = $stateParams.id;

    var uploadList = [] ;

    for(var i =0; i< 5; i++){

        var uploader = new FileUploader({
            url: '/uj-admin/winery/upload',
            index: i
        });
        // FILTERS
        uploader.filters.push({
            name: 'imageFilter',
            fn: function(item /*{File|FileLikeObject}*/, options) {
                var type = '|' + item.type.slice(item.type.lastIndexOf('/') + 1) + '|';
                return '|jpg|png|jpeg|bmp|gif|'.indexOf(type) !== -1;
            }
        });

        uploader.onAfterAddingFile = function(fileItem) {
            fileItem.formData.push({"index": this.index});
            fileItem.formData.push({"id": $stateParams.id});
            fileItem.upload();
        };

        uploader.onSuccessItem = function(fileItem, response, status, headers) {
            $("#img" + this.index).attr("src", $("#img" + this.index).attr("src")+"?timestamp=" + new Date().getTime());
        };

        uploader.onErrorItem = function(fileItem, response, status, headers) {
            if(response.errorCode == "LoginRequired")
            {
                window.location = '/uj-admin';
                return;
            }

            alert("请上传像素大于800*800的图片");
        };
        uploadList.push(uploader);
    }


    $scope.uploader0 = uploadList[0];
    $scope.uploader1 = uploadList[1];
    $scope.uploader2 = uploadList[2];
    $scope.uploader3 = uploadList[3];
    $scope.uploader4 = uploadList[4];



});

adminApp.controller('inventoryFormCtrl', function($scope,$http,$state,$stateParams,inventoryService){
    $scope.inventory = {};
    $scope.state = 1;

    inventoryService.getInventoryById($stateParams.id).success(function(data){
        if(data == null || data == ""){
            $scope.inventory.stock = 0;
            $scope.inventory.goods_id = $stateParams.id;
            $scope.state = 0;
        }
        else{
            $scope.inventory = data;
        }
    })

    $scope.name = $stateParams.name;

    $scope.save = function(){
        if($scope.state == 0){
            $http.put('/uj-admin/inventory/add', $scope.inventory).success(function(data){
                $state.go('index.goodsMng');
            })
        }
        else{
            $http.put('/uj-admin/inventory/edit', $scope.inventory).success(function(data){
                $state.go('index.goodsMng');
            })
        }
    }
});

adminApp.controller('categoryMngCtrl', function($scope,$http,$state,$stateParams,categoryService){
    $scope.parentList = [];

    categoryService.getCategoryList().success(function(data){
        $scope.list = data;
        for(var i = 0;i < $scope.list.length;i ++){
            if($scope.list[i].parent_id == 0){
                $scope.category = $scope.list[i];
                $scope.parentList.push($scope.category);
                $scope.list.splice(i,1);
                i--;
            }
        }
        for(var i = 0;i < $scope.parentList.length;i ++){

        }
    })
});

adminApp.controller('parametersMngCtrl',function($scope,$http,$state,$stateParams,$location,parametersService){
    $scope.search = {};

    parametersService.getParametersList().success(function(data){
        $scope.list = data;
    });

    $scope.delete = function(id){
        $http.delete('/uj-admin/parameters/' + id).success(function(data){
            for(var i = 0;i < $scope.list.length ; i++){
                if($scope.list[i].id == id){
                    $scope.list.splice(i,1);
                    return;
                }
            }
        })
    }

});

adminApp.controller('parametersFormCtrl',function($scope,$http,$state,$stateParams,parametersService){
    if($stateParams.id > 0){
        $scope.operation = true;
        parametersService.getById($stateParams.id).success(function(data){
            $scope.parameter = data;
        })
    }
    else{
        $scope.operation = false;
    }

    $scope.save = function(){
        if($stateParams.id > 0){
            $http.put('/uj-admin/parameters', $scope.parameter).success(function(data){
                $state.go('index.parametersMng');
            })
        }
        else{
            $http.post('/uj-admin/parameters/add', $scope.parameter).success(function(data){
                $state.go('index.parametersMng');
            })
        }
    }
});

adminApp.controller('memberMngCtrl', function($scope,$http,$state,$stateParams,memberService){
    $scope.search = {};
    $scope.search.pageIndex = 0;
    $scope.search.pageSize = 10;

    $scope.getPagedDataAsync = function(){
        $http.post("/uj-admin/member/list", $scope.search).success(function(data){

            $scope.list = data.list;
            $scope.count = data.count;
        });

    };

    $scope.pagedCallback = function (){
        $scope.search.pageIndex = $scope.pageIndex -1;
        $scope.getPagedDataAsync();
    };

    $scope.getPagedDataAsync();
});

adminApp.controller('memberFormCtrl',function($scope,$http,$state,$stateParams,memberService){
    memberService.getById($stateParams.id).success(function(data){
        $scope.member = data;
    })
});

adminApp.controller('orderMngCtrl',function($scope,$http,$state,$stateParams){
    $scope.search = {};
    $scope.search.pageIndex = 0;
    $scope.search.pageSize = 10;

    $scope.getPagedDataAsync = function(){
        $http.post("/uj-admin/order/list", $scope.search).success(function(data){

            $scope.list = data.list;
            $scope.count = data.count;
        });

    };

    $scope.pagedCallback = function (){
        $scope.search.pageIndex = $scope.pageIndex -1;
        $scope.getPagedDataAsync();
    };

    $scope.showDetail = function(id){
        $scope.selectedOrderId = id;
    };

    $scope.getPagedDataAsync();
});

adminApp.controller('orderDetailCtrl',function($scope,$http,$state,$stateParams,orderService){
    orderService.getById($stateParams.id).success(function(data){
        $scope.order = data;
        if(data.deliveryType == 0 && typeof(data.storeId) != "undefined"){
            $http.get("/uj-admin/store/" + data.storeId).success(function(result){
                $scope.store = result;
            });
        }
    });

    $scope.getShippedInfo = function(){
        $http.get("/uj-admin/order/mylist/" + $stateParams.id).success(function(data){
            $scope.myListMember = data;
        });
    };

    $scope.shippingInfo = function(){

        $http.put("/uj-admin/shippingInfo", $scope.order).success(function(data){

            $scope.order = data;
            $("#shippingInfoModal").modal('hide');
        }).error(function(){
            alert("!");
        })
    }

    $scope.shipOrder = function(){
        $http.put("/uj-admin/shipOrder/" + $stateParams.id).success(function(data){
            $scope.order = data;
            $("#shippedModal").modal('hide');
        });

    };
});


adminApp.controller('repurchaseMngCtrl',function($scope,$http,$state,$stateParams){
    $scope.search = {};
    $scope.search.pageIndex = 0;
    $scope.search.pageSize = 10;

    $scope.getPagedDataAsync = function(){
        $http.post("/uj-admin/repurchase/list", $scope.search).success(function(data){

            $scope.list = data.list;
            $scope.count = data.count;
        });

    };

    $scope.pagedCallback = function (){
        $scope.search.pageIndex = $scope.pageIndex -1;
        $scope.getPagedDataAsync();
    };

    $scope.getPagedDataAsync();
});

adminApp.controller('repurchaseFormCtrl',function($scope,$http,$state,$stateParams,parametersService){

    $http.get("/uj-admin/repurchase/" + $stateParams.id).success(function(data){
        $scope.repurchase = data;
    });


    $scope.save = function(){

        $http.put('/uj-admin/repurchase', {'id':$stateParams.id , 'price': $scope.repurchase.price}).success(function(data){
            $state.go('index.repurchaseMng');
        })


    }
});


adminApp.controller('activityMngCtrl',function($scope,$http,FileUploader){

    $http.get("/uj-admin/activity/get").success(function(data){
        var content=JSON.parse(data.content);
        $("#description").val(content.description);
        $(".activityForm .row").each(function(a,e){
            var activity=content.activities[a];
            $(e).find(".actId").val(activity.id);
            $(e).find(".title").val(activity.title);
            $(e).find(".link").val(activity.link);
            $(e).find(".pids").val(activity.pids);
            $(e).find(".description").val(activity.description);
        });
    });

    var uploadList = [] ;
    for(var i =0; i< 3; i++){
        var uploader = new FileUploader({
            url: '/uj-admin/activity/upload',
            index: i
        });
        // FILTERS
        uploader.filters.push({
            name: 'imageFilter',
            fn: function(item /*{File|FileLikeObject}*/, options) {
                var type = '|' + item.type.slice(item.type.lastIndexOf('/') + 1) + '|';
                return '|jpg|png|jpeg|bmp|gif|'.indexOf(type) !== -1;
            }
        });

        uploader.onAfterAddingFile = function(fileItem) {
            fileItem.formData.push({"index": this.index});
            fileItem.upload();
        };

        uploader.onSuccessItem = function(fileItem, response, status, headers) {
            $("#img" + this.index).attr("src", $("#img" + this.index).attr("src")+"?timestamp=" + new Date().getTime());
        };

        uploader.onErrorItem = function(fileItem, response, status, headers) {

        };
        uploadList.push(uploader);
    };

    $scope.uploader0 = uploadList[0];
    $scope.uploader1 = uploadList[1];
    $scope.uploader2 = uploadList[2];

    $scope.save=function(){
        var content= {activities:[]};
        $(".activityForm .row").each(function(a,e){

            var activity={id:"",title:"",link:"",pids:""};
            activity.id=a;
            activity.title=$(e).find(".title").val();
            activity.link=$(e).find(".link").val();
            activity.pids=$(e).find(".pids").val();
            activity.description= $(e).find(".description").val(),
            content.activities.push(activity);
        });
        var contentStr=JSON.stringify(content);
        var activity={content:contentStr};
        $http.post("/uj-admin/activity/save/",activity).success(function(data){
            alert("更新成功!");
        });
    };

    $scope.test=function(){
        $http.post("/uj-admin/activity").success(function(data){
            alert("Successful");
        });
    }
});

adminApp.controller('withdrawMngCtrl', function($scope,$http,$state,$stateParams,memberService){
    $scope.search = {};
    $scope.withdraw = {};
    $scope.search.pageIndex = 0;
    $scope.search.pageSize = 10;

    $scope.getPagedDataAsync = function(){
        $http.post("/uj-admin/withdraw/list", $scope.search).success(function(data){

            $scope.list = data.list;
            $scope.count = data.count;
        });

    };

    $scope.pagedCallback = function (){
        $scope.search.pageIndex = $scope.pageIndex -1;
        $scope.getPagedDataAsync();
    };

    $scope.getPagedDataAsync();

    $scope.getRecord = function(item){
        $scope.withdraw.id = item.id;
        $scope.withdraw.memberId = item.memberId;
        $scope.withdraw.amount = item.amount;
        $scope.withdraw.status = 1;
        $scope.withdraw.cancelReason = "";
    }

    $scope.sendMessage = function(){
        $http.post("/uj-admin/withdraw/transfer",$scope.withdraw).success(function(data){
            $scope.getPagedDataAsync();
            $("#transferModal").modal('hide');
        })
    }
});

adminApp.controller('topBannerMngCtrl', function($scope,$http,$state,$stateParams,$location,wineryService){
    $scope.search = {};

    $http.get("/uj-admin/topBanner/list").success(function(data){

        $scope.list = data;
    });

    $scope.delete = function(id){
        $http.delete('/uj-admin/topBanner/' + id).success(function(data){
            for(var i = 0;i < $scope.list.length ; i++){
                if($scope.list[i].id == id){
                    $scope.list.splice(i,1);
                    return;
                }
            }
        })
    }
});

adminApp.controller('topBannerFormCtrl', function($scope,$http,$state,$stateParams){
    if($stateParams.id > 0){
        $http.get("/uj-admin/topBanner/" + $stateParams.id).success(function(data){
            $scope.topBanner = data;
        })
    }

    $scope.save = function(){
        if($stateParams.id > 0){
            $http.put('/uj-admin/topBanner', $scope.topBanner).success(function(data){
                $state.go('index.topBannerMng');
            })
        }
        else{
            $http.post('/uj-admin/topBanner', $scope.topBanner).success(function(data){
                $state.go('index.topBannerMng');
            })
        }
    }
});

adminApp.controller('topBannerUploadCtrl' , function($scope,$http,$state,$stateParams, FileUploader){
    $scope.id = $stateParams.id;

        var uploader = new FileUploader({
            url: '/uj-admin/topBanner/upload'
        });
        // FILTERS
        uploader.filters.push({
            name: 'imageFilter',
            fn: function(item /*{File|FileLikeObject}*/, options) {
                var type = '|' + item.type.slice(item.type.lastIndexOf('/') + 1) + '|';
                return '|jpg|png|jpeg|bmp|gif|'.indexOf(type) !== -1;
            }
        });

        uploader.onAfterAddingFile = function(fileItem) {
            fileItem.formData.push({"id": $stateParams.id});
            fileItem.upload();
        };

        uploader.onSuccessItem = function(fileItem, response, status, headers) {
            $("#img").attr("src", $("#img").attr("src")+"?timestamp=" + new Date().getTime());
        };

        uploader.onErrorItem = function(fileItem, response, status, headers) {
            if(response.errorCode == "LoginRequired")
            {
                window.location = '/uj-admin';
                return;
            }
            alert("请上传像素大于800*800的图片");
        };

    $scope.uploader = uploader;


});

adminApp.controller('storeMngCtrl', function($scope,$http,$state,$stateParams,$location,wineryService){


    $http.get("/uj-admin/store/list").success(function(data){

        $scope.list = data;
    });

    $scope.delete = function(id){
        $http.delete('/uj-admin/store/' + id).success(function(data){
            for(var i = 0;i < $scope.list.length ; i++){
                if($scope.list[i].id == id){
                    $scope.list.splice(i,1);
                    return;
                }
            }
        })
    }
});

adminApp.controller('storeFormCtrl', function($scope,$http,$state,$stateParams){

    $scope.address = {};

    if($stateParams.id > 0){
        $http.get("/uj-admin/store/" + $stateParams.id).success(function(data){

            $scope.store = data;
            $scope.address = $scope.store;
            $scope.searchByStationName();
        });
    }else{
        $scope.store = {};
        $scope.address = $scope.store;

    }




    $scope.save = function(){
        if($stateParams.id > 0){
            $http.put('/uj-admin/store', $scope.store).success(function(data){
                $state.go('index.storeMng');
            })
        }
        else{
            $http.post('/uj-admin/store', $scope.store).success(function(data){
                $state.go('index.storeMng');
            })
        }
    };

    var map = new BMap.Map("container");
    map.centerAndZoom("厦门", 12);
    map.enableScrollWheelZoom();    //启用滚轮放大缩小，默认禁用
    map.enableContinuousZoom();    //启用地图惯性拖拽，默认禁用

/*   map.addControl(new BMap.NavigationControl());  //添加默认缩放平移控件
    map.addControl(new BMap.OverviewMapControl()); //添加默认缩略地图控件
    map.addControl(new BMap.OverviewMapControl({ isOpen: true, anchor: BMAP_ANCHOR_BOTTOM_RIGHT }));   //右下角，打开*/

    var localSearch = new BMap.LocalSearch(map);
    localSearch.enableAutoViewport(); //允许自动调节窗体大小

    $scope.searchByStationName = function(){
        map.clearOverlays();//清空原来的标注
        var keyword = "";
        if(typeof($scope.store.province) != "undefined")
            keyword += $scope.store.province;
        if(typeof($scope.store.city) != "undefined")
            keyword += $scope.store.city;
        if(typeof($scope.store.county) != "undefined")
            keyword += $scope.store.county;
        if(typeof($scope.store.address) != "undefined")
            keyword += $scope.store.address;
        localSearch.setSearchCompleteCallback(function (searchResult) {
            var poi = searchResult.getPoi(0);
            //document.getElementById("result_").value = poi.point.lng + "," + poi.point.lat;
            $scope.store.longitude = poi.point.lng;
            $scope.store.latitude = poi.point.lat;
            map.centerAndZoom(poi.point, 17);
            var marker = new BMap.Marker(new BMap.Point(poi.point.lng, poi.point.lat));  // 创建标注，为要查询的地方对应的经纬度
            map.addOverlay(marker);

            var content = $scope.store.address + "<br/><br/>经度：" + poi.point.lng + "<br/>纬度：" + poi.point.lat;
            var infoWindow = new BMap.InfoWindow("<p style='font-size:14px;'>" + content + "</p>");
            marker.addEventListener("click", function () { marker.openInfoWindow(infoWindow) });

            $(".alert-danger").hide();
            $(".alert-success").show();
            //marker.setAnimation(BMAP_ANIMATION_BOUNCE); //跳动的动画
        });
        localSearch.search(keyword);
    }
});

adminApp.controller('storeUploadCtrl' , function($scope,$http,$state,$stateParams, FileUploader){
    $scope.id = $stateParams.id;

    var uploader = new FileUploader({
        url: '/uj-admin/store/upload'
    });
    // FILTERS
    uploader.filters.push({
        name: 'imageFilter',
        fn: function(item /*{File|FileLikeObject}*/, options) {
            var type = '|' + item.type.slice(item.type.lastIndexOf('/') + 1) + '|';
            return '|jpg|png|jpeg|bmp|gif|'.indexOf(type) !== -1;
        }
    });

    uploader.onAfterAddingFile = function(fileItem) {
        fileItem.formData.push({"id": $stateParams.id});
        fileItem.upload();
    };

    uploader.onSuccessItem = function(fileItem, response, status, headers) {
        $("#img").attr("src", $("#img").attr("src")+"?timestamp=" + new Date().getTime());
    };

    uploader.onErrorItem = function(fileItem, response, status, headers) {
        if(response.errorCode == "LoginRequired")
        {
            window.location = '/uj-admin';
            return;
        }
        alert("请上传像素大于800*800的图片");
    };

    $scope.uploader = uploader;

});
